package cn.iocoder.yudao.module.api.pay.refund.vo;

import cn.iocoder.yudao.module.api.pay.refund.enums.UnifiedRefundStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * 退款单信息 Response DTO
 *
 * @author 芋道源码
 */
@Data
@Accessors(chain = true)
public class UnifiedRefundVO {

    /**
     * 退款状态
     *
     * @see UnifiedRefundStatusEnum
     */
    private Integer status;

    /**
     * 退款单号
     * 对应 PayRefundDO 的 no 字段
     */
    private String refundNo;

    /**
     * 渠道退款单号
     * 对应 PayRefundDO.channelRefundNo 字段
     */
    private String channelRefundNo;

    /**
     * 退款成功时间
     */
    private LocalDateTime successTime;

    /**
     * 原始的异步通知结果
     */
    private Object rawData;

    /**
     * 调用渠道的错误码
     */
    private String channelErrorCode;
    /**
     * 调用渠道报错时，错误信息
     */
    private String channelErrorMsg;

    private UnifiedRefundVO() {
        super();
    }

    /**
     * 创建【WAITING】状态的退款返回
     */
    public static UnifiedRefundVO waitingOf(String channelRefundNo, String refundNo, Object rawData) {
        UnifiedRefundVO respDTO = new UnifiedRefundVO();
        respDTO.status = UnifiedRefundStatusEnum.WAITING.getStatus();
        respDTO.channelRefundNo = channelRefundNo;
        // 相对通用的字段
        respDTO.refundNo = refundNo;
        respDTO.rawData = rawData;
        return respDTO;
    }

    /**
     * 创建【SUCCESS】状态的退款返回
     */
    public static UnifiedRefundVO successOf(String channelRefundNo, LocalDateTime successTime, String refundNo, Object rawData) {
        UnifiedRefundVO respDTO = new UnifiedRefundVO();
        respDTO.status = UnifiedRefundStatusEnum.SUCCESS.getStatus();
        respDTO.channelRefundNo = channelRefundNo;
        respDTO.successTime = successTime;
        // 相对通用的字段
        respDTO.refundNo = refundNo;
        respDTO.rawData = rawData;
        return respDTO;
    }

    /**
     * 创建【FAILURE】状态的退款返回
     */
    public static UnifiedRefundVO failureOf(String refundNo, Object rawData) {
        return failureOf(null, null, refundNo, rawData);
    }

    /**
     * 创建【FAILURE】状态的退款返回
     */
    public static UnifiedRefundVO failureOf(String channelErrorCode, String channelErrorMsg, String refundNo, Object rawData) {
        UnifiedRefundVO respDTO = new UnifiedRefundVO();
        respDTO.status = UnifiedRefundStatusEnum.FAILURE.getStatus();
        respDTO.channelErrorCode = channelErrorCode;
        respDTO.channelErrorMsg = channelErrorMsg;
        // 相对通用的字段
        respDTO.refundNo = refundNo;
        respDTO.rawData = rawData;
        return respDTO;
    }

}
